package cc.kzc.adminauth.auth;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import com.alibaba.fastjson2.JSON;

import cc.kzc.adminauth.common.BaseResponse;
import cc.kzc.adminauth.common.ErrorCode;

public class UserAuthenticationEntryPoint implements AuthenticationEntryPoint {

	@Override
	public void commence(HttpServletRequest request, HttpServletResponse response,
			AuthenticationException authException) throws IOException, ServletException {

		response.setContentType("application/json;charset=UTF-8");
		response.setStatus(HttpStatus.OK.value());
		response.getWriter().write(JSON.toJSONString(BaseResponse.fail(ErrorCode.CLI_UNAUTHORIZED, "登录信息不正确！")));
		response.getWriter().flush();
	}
}
